﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CardGenerateTower : AbstractTower {
    public Transform CardGeneratePivot;
    public GameObject CardPrefab;

    public VRControllerInteractive cardContollerInteractive;
    public bool hasCard;

    public float generateTimer;
    public float generateTime;


    public void Update()
    {
        if (!hasCard && TowerOwner!= PlayerType.None)
        {
            generateTimer += Time.deltaTime;
            if (generateTimer > generateTime)
            {
                GameObject g =Instantiate(CardPrefab, CardGeneratePivot.position, CardGeneratePivot.rotation);
                cardContollerInteractive = g.GetComponent<VRControllerInteractive>();
                g.GetComponent<FallMagicCard  >().CardOwner = TowerOwner;
                cardContollerInteractive.StartHolding += RegenerateCard;
                hasCard = true;
                generateTimer = 0;
            }
        }
    }

    public void RegenerateCard()
    {
        cardContollerInteractive.StartHolding -= RegenerateCard;
        cardContollerInteractive = null;
        hasCard = false;
    }

}
